package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlGradeGradesHistory entities. Transaction control of the save(), update()
 * and delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlGradeGradesHistory
 * @author MyEclipse Persistence Tools
 */

public class MdlGradeGradesHistoryDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlGradeGradesHistoryDAO.class);
	// property constants
	public static final String ACTION = "action";
	public static final String OLDID = "oldid";
	public static final String SOURCE = "source";
	public static final String TIMEMODIFIED = "timemodified";
	public static final String LOGGEDUSER = "loggeduser";
	public static final String ITEMID = "itemid";
	public static final String USERID = "userid";
	public static final String RAWGRADE = "rawgrade";
	public static final String RAWGRADEMAX = "rawgrademax";
	public static final String RAWGRADEMIN = "rawgrademin";
	public static final String RAWSCALEID = "rawscaleid";
	public static final String USERMODIFIED = "usermodified";
	public static final String FINALGRADE = "finalgrade";
	public static final String HIDDEN = "hidden";
	public static final String LOCKED = "locked";
	public static final String LOCKTIME = "locktime";
	public static final String EXPORTED = "exported";
	public static final String OVERRIDDEN = "overridden";
	public static final String EXCLUDED = "excluded";
	public static final String FEEDBACK = "feedback";
	public static final String FEEDBACKFORMAT = "feedbackformat";
	public static final String INFORMATION = "information";
	public static final String INFORMATIONFORMAT = "informationformat";

	public void save(MdlGradeGradesHistory transientInstance) {
		log.debug("saving MdlGradeGradesHistory instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlGradeGradesHistory persistentInstance) {
		log.debug("deleting MdlGradeGradesHistory instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlGradeGradesHistory findById(java.lang.Long id) {
		log.debug("getting MdlGradeGradesHistory instance with id: " + id);
		try {
			MdlGradeGradesHistory instance = (MdlGradeGradesHistory) getSession()
					.get("idv.loveloser.dao.MdlGradeGradesHistory", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlGradeGradesHistory instance) {
		log.debug("finding MdlGradeGradesHistory instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlGradeGradesHistory")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlGradeGradesHistory instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlGradeGradesHistory as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByAction(Object action) {
		return findByProperty(ACTION, action);
	}

	public List findByOldid(Object oldid) {
		return findByProperty(OLDID, oldid);
	}

	public List findBySource(Object source) {
		return findByProperty(SOURCE, source);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findByLoggeduser(Object loggeduser) {
		return findByProperty(LOGGEDUSER, loggeduser);
	}

	public List findByItemid(Object itemid) {
		return findByProperty(ITEMID, itemid);
	}

	public List findByUserid(Object userid) {
		return findByProperty(USERID, userid);
	}

	public List findByRawgrade(Object rawgrade) {
		return findByProperty(RAWGRADE, rawgrade);
	}

	public List findByRawgrademax(Object rawgrademax) {
		return findByProperty(RAWGRADEMAX, rawgrademax);
	}

	public List findByRawgrademin(Object rawgrademin) {
		return findByProperty(RAWGRADEMIN, rawgrademin);
	}

	public List findByRawscaleid(Object rawscaleid) {
		return findByProperty(RAWSCALEID, rawscaleid);
	}

	public List findByUsermodified(Object usermodified) {
		return findByProperty(USERMODIFIED, usermodified);
	}

	public List findByFinalgrade(Object finalgrade) {
		return findByProperty(FINALGRADE, finalgrade);
	}

	public List findByHidden(Object hidden) {
		return findByProperty(HIDDEN, hidden);
	}

	public List findByLocked(Object locked) {
		return findByProperty(LOCKED, locked);
	}

	public List findByLocktime(Object locktime) {
		return findByProperty(LOCKTIME, locktime);
	}

	public List findByExported(Object exported) {
		return findByProperty(EXPORTED, exported);
	}

	public List findByOverridden(Object overridden) {
		return findByProperty(OVERRIDDEN, overridden);
	}

	public List findByExcluded(Object excluded) {
		return findByProperty(EXCLUDED, excluded);
	}

	public List findByFeedback(Object feedback) {
		return findByProperty(FEEDBACK, feedback);
	}

	public List findByFeedbackformat(Object feedbackformat) {
		return findByProperty(FEEDBACKFORMAT, feedbackformat);
	}

	public List findByInformation(Object information) {
		return findByProperty(INFORMATION, information);
	}

	public List findByInformationformat(Object informationformat) {
		return findByProperty(INFORMATIONFORMAT, informationformat);
	}

	public List findAll() {
		log.debug("finding all MdlGradeGradesHistory instances");
		try {
			String queryString = "from MdlGradeGradesHistory";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlGradeGradesHistory merge(MdlGradeGradesHistory detachedInstance) {
		log.debug("merging MdlGradeGradesHistory instance");
		try {
			MdlGradeGradesHistory result = (MdlGradeGradesHistory) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlGradeGradesHistory instance) {
		log.debug("attaching dirty MdlGradeGradesHistory instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlGradeGradesHistory instance) {
		log.debug("attaching clean MdlGradeGradesHistory instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}